package com.suanfa;


import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * 基本查找
 *
 * @Author weijingchen
 * @Date 2025/5/27 21:40
 * @Version 1.0.0
 */
public class Test04 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 3, 7, 8, 9, 10};
        int num = 3;



        boolean b = binarySearch(arr, num);
        System.out.println(b);
        ArrayList<Integer> integers = binarySearch2(arr, num);
        System.out.println(integers);
    }

    /**
     * 普通查找，不考虑是否重复
     */
    public static boolean binarySearch(int[] arr, int num) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num) {
                return true;
            }
        }
        return false;
    }

    /**
     * 普通查找，考虑重复情况
     */

    public static ArrayList<Integer> binarySearch2(int[] arr, int num) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num) {
                System.out.println("存在" + num + " 在arr数组的" + i + "位置");
                list.add(i);
            }
        }
        return list;
    }
}
